

using System;
using System.Web.Security;
using System.Collections.Generic;

using Grr;
using Grr.Models;

using Castle.MonoRail.Framework;


namespace Grr.Controllers {

    [Layout("moderator")]
    public class ModeratorController : SmartDispatcherController {

	public void Index()
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }
	}

	public void UnmoderatedGrurrahs ()
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    PropertyBag["grurrahs"] = Grurrah.GetUnmoderatedGrurrahs();
	}
	 

	public void ApproveGrurrah(long id)
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    Grurrah.Approve(id);

	    RedirectToAction ("UnmoderatedGrurrahs");
	}

	public void DeleteGrurrah(long id)
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    Grurrah.Delete(id);

	    RedirectToAction ("UnmoderatedGrurrahs");
	}


	public void ApproveRevision(long id)
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    Revision.Approve(id);

	    RedirectToAction("UnmoderatedRevisions");
	}

	public void DeleteRevision(long revision_id, long grurrah_id)
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    Revision.Delete(revision_id, grurrah_id);

	    RedirectToAction("UnmoderatedRevisions");
	}

	public void UnmoderatedRevisions()
	{
	    if (!Roles.IsUserInRole("Moderators")) {
		RenderView("not_logged_in");
		return;
	    }

	    PropertyBag["revisions"] = Revision.GetUnmoderatedRevisions();
	}
    }
}

